package top.flvio.middleware.test;

import org.junit.Test;
import top.flvio.middleware.annotation.DBRouter;

import java.lang.reflect.Method;

/**
 * @description: api测试
 * @author: flvio
 * @date: 2025/2/9
 */
public class ApiTest
{
    @Test
    public void test_db_hash(){
        String key = "flviostata";

        int dbCount = 2, tbCount = 4;
        int size = dbCount * tbCount;

        //散列
        int idx = (size - 1) & (key.hashCode() >>> 16);

        int dbIdx = idx / tbCount + 1;
        int tbIdx = idx - tbCount * (dbIdx - 1);

        System.out.println(dbIdx);
        System.out.println(tbIdx);
    }

    @Test
    public void test_str_format(){
        System.out.println(String.format("db%20d",1));
        System.out.println(String.format("_%02d",25));
    }

    @Test
    public void test_annotation() throws NoSuchMethodException
    {
        Class<IUserDao> iUserDaoClass = IUserDao.class;
        Method method = iUserDaoClass.getMethod("insertUser", String.class);

        DBRouter dbRouter = method.getAnnotation(DBRouter.class);

        System.out.println(dbRouter.key());
    }
}
